import type { ImgPreviewOptions } from './type'

import { createVNode, render } from 'vue'

import ImgPreview from './Functional.vue'

let instance: null | ReturnType<typeof createVNode> = null
/** 图片浏览 */
export function createImgPreview(options: ImgPreviewOptions) {
  const propsData: Partial<ImgPreviewOptions> = {}
  const container = document.createElement('div')
  Object.assign(propsData, { show: true }, options)

  instance = createVNode(ImgPreview, propsData)
  render(instance, container)
  document.body.append(container)
  return instance.component?.exposed
}
